import java.util.*;

public class dajiang {
    //2 7 1 3 5
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] s1 = s.split(" ");
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < s1.length; i++) {
            map.put(i,Integer.valueOf(s1[i]));
        }

        Comparator<Map.Entry<Integer,Integer>> valCom = new Comparator<Map.Entry<Integer, Integer>>() {
            @Override
            public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
                return o2.getValue()-o1.getValue();
            }
        };

        List<Map.Entry<Integer,Integer>> list = new ArrayList<Map.Entry<Integer,Integer>>(map.entrySet());
        Collections.sort(list,valCom);

        int[] shuju = new int[s1.length];
        for (int i = 0; i < shuju.length; i++) {
            shuju[i] = -2;
        }
        int count = 0;
        for (int i = 0; i < list.size(); i++) {

            Map.Entry<Integer, Integer> entry = list.get(i);
            Integer key = entry.getKey();
            shuju[i] = key;
            Integer value = entry.getValue();
            if(fangfa(key,shuju)){
                count += value;
            }
        }
        System.out.println(count);
    }

    private static boolean fangfa(Integer key , int[] shuju){
        for (int i = 0; i < shuju.length; i++) {
            if(key==shuju[i]+1 || key==shuju[i]-1){
                return false;
            }
        }
        return true;
    }
}
